import { DataSource } from 'typeorm';
import config from '../app.config';

export const DBRepository = new DataSource({
  type: 'mssql',
  host: config.DB.HOST ? config.DB.HOST : '192.168.1.240',
  port: config.DB.PORT ? config.DB.PORT : 1433,
  username: config.DB.USERNAME ? config.DB.USERNAME : 'sa',
  password: config.DB.PASSWORD ? config.DB.PASSWORD : 'THth@2023',
  database: config.DB.DATABASE ? config.DB.DATABASE : 'riverbed',
  entities: [__dirname + '/**/*.entity{.ts,.js}'],
  logging: ['query'], // 启用日志记录
});

DBRepository.initialize()
  .then(() => {
    console.log('Data Source has been initialized!');
  })
  .catch((err) => {
    console.error('Error during Data Source initialization', err);
  });
